<?

/**
* local collection functions of tocmenu_Y1
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @copyright Copyright (c)2007, Adesanto Asman
* @package CLFetchers
*
*/

/**
* @package CLFetchers
*
*/
class CLFetchers{

  /**
  * fetch the list of valid transactions
  *
  * @param  string    $Db
  * @param  string    $condt      the condition
  * @param  string    $srcDb
  * @param  string    $lstResult
  *
  */
  function fetchLstTransaction(&$Db,
                               $condt,
        	                     &$srcDb,
        	                     &$nResult,
        	                     &$lstResult){

    $query  = "SELECT USERID,
                      USERNAME,
                      COMPANY,
                      POS,
                      DEPARTMENT,
                      STATUS
               FROM ".$srcDb."
               ".$condt."
               ORDER BY USERID DESC ";

    $Db->execFetchQuery($query,
                        $nResult,
                        $lstResult);
  }

  /**
  * fetch access list
  *
  * @param  string    $Db
  * @param  string    $srcDb
  * @param  string    $nAccess
  * @param  string    $lstAccess
  *
  */
  function fetchLstAccess(&$Db,
                          &$srcDb,
                          &$nAccess,
                          &$lstAccess){

    $query  = "SELECT TRANSACTION AS DESCRIPTION,
                      LEVELMN
               FROM ".$srcDb."
               WHERE  STATUS='"._ACTIVE."'
               ORDER BY LEVELMN ASC";

    $Db->execFetchQuery($query,
                        $nAccess,
                        $lstAccess);

  }

  /**
  * fetch list of pos
  *
  * @param  string    $Db
  * @param  string    $srcDb
  * @param  string    $nPos
  * @param  string    $lstPos
  *
  */
  function fetchLstPos(&$Db,
                       &$srcDb,
                       &$nPos,
                       &$lstPos){

    $query  = "SELECT POS
               FROM ".$srcDb."
               WHERE  STATUS=1
               ORDER BY POS_ID ASC";

    $Db->execFetchQuery($query,
                        $nPos,
                        $result);

    $lstPos = $result["POS"];
  }

  /**
  * fetch list of department
  *
  * @param  string    $Db
  * @param  string    $srcDb
  * @param  string    $nDept
  * @param  string    $lstDept
  *
  */
  function fetchLstDept(&$Db,
                        &$srcDb,
                        &$nDept,
                        &$lstDept){

    $query  = "SELECT DEPT
               FROM ".$srcDb."
               WHERE  STATUS=1
               ORDER BY DEPT_ID ASC";

    $Db->execFetchQuery($query,
                        $nDept,
                        $result);

    $lstDept = $result["DEPT"];
  }

  /**
  * fetch list of company
  *
  * @param  string    $Db
  * @param  string    $srcDb
  * @param  string    $nCompany
  * @param  string    $lstCompany
  *
  */
  function fetchLstCompany(&$Db,
                           &$srcDb,
                           &$nCompany,
                           &$lstCompany){

    $query  = "SELECT COMPANY
               FROM ".$srcDb."
               ORDER BY COMPANY ASC";

    $Db->execFetchQuery($query,
                        $nCompany,
                        $result);

    $lstCompany = $result["COMPANY"];
  }

  /**
  * fetch userid header
  *
  * @param  string  $Db
  * @param  string  $usrId
  * @param  string  $usrComp
  * @param  string  $srcDb
  * @param  string  $nHdr
  * @param  string  $resHdr
  *
  */
  function fetchUsrHdr(&$Db,
                       &$usrId,
                       &$usrComp,
                       &$srcDb,
                       &$nHdr,
                       &$resHdr){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  USERID='".$usrId."'
                      AND COMPANY='".$usrComp."' ";

    $Db->execFetchQuery($query,
                        $nHdr,
                        $resHdr);
  }

  /**
  * fetch userid detail
  *
  * @param  string  $Db
  * @param  string  $usrId
  * @param  string  $usrComp
  * @param  string  $srcDb
  * @param  string  $nDtl
  * @param  string  $resDtl
  *
  */
  function fetchUsrDtl(&$Db,
                       &$usrId,
                       &$usrComp,
                       &$srcDb,
                       &$nDtl,
                       &$resDtl){

    $query  = "SELECT *
               FROM ".$srcDb."
               WHERE  USERID='".$usrId."'
                      AND COMPANY='".$usrComp."'
               ORDER BY LEVELMN ASC ";

    $Db->execFetchQuery($query,
                        $nDtl,
                        $resDtl);
  }

  /**
  * Fetch the group privs template
  *
  * @param  string $Db
  * @param  string $srcPos
  * @param  string $srcDept
  * @param  string $srcDbHdr
  * @param  string $srcDbDtl
  * @param  string $nTimes
  * @param  string $lstGroupPrivs
  *
  */
  function fetchGroupPrivs(&$Db,
                           &$srcPos,
                           &$srcDept,
                           &$srcDbGrpHdr,
                           &$srcDbGrpDtl,
                           &$srcDbPos,
                           &$srcDbDept,
                           &$nTimes,
                           &$lstGroupPrivs){

    $query  = "SELECT ".$srcDbGrpDtl.".*

               FROM ".$srcDbGrpDtl.",
                    ".$srcDbGrpHdr.",
                    ".$srcDbPos.",
                    ".$srcDbDept."

               WHERE  ".$srcDbPos.".POS='".$srcPos."'

                      AND ".$srcDbGrpHdr.".POS_ID=".$srcDbPos.".POS_ID

                      AND ".$srcDbDept.".DEPT='".$srcDept."'

                      AND ".$srcDbGrpHdr.".DEPT_ID=".$srcDbDept.".DEPT_ID

                      AND ".$srcDbGrpHdr.".GROUP_ID=".$srcDbGrpDtl.".GROUP_ID

               ORDER BY ".$srcDbGrpDtl.".NO ASC ";

    $Db->execFetchQuery($query,
                        $nTimes,
                        $lstGroupPrivs);
  }

  /**
   * check if id is exists
   *
   * @param string  $Db
   * @param string  $thisId
   * @param string  $srcDb
   * @param boolean $isExists
   */
  function fetchIsIdExists(&$Db,
                           &$thisId,
                           &$srcDb,
                           &$isExists){

  	$query = "SELECT USERID
  	          FROM ".$srcDb."
  	          WHERE  USERID='".$thisId."' ";

  	$Db->execFetchQuery($query,
  	                    $nrows,
  	                    $result);

    if($nrows > 0){

    	$isExists = 1;
    }else{

    	$isExists = 0;
    }
  }
}

?>